/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.parser.iq.props;

import java.util.ArrayList;

import com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALIQ;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.ALBaseIQParser;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.IQXmlParseEventCallback;
import com.alstudio.pojo.module.local.Prop;
import com.alstudio.utils.formater.numeric.ALNumericUtils;
import com.alstudio.utils.log.ALLog;

/**
 * 用户道具购买明细
 * 
 * @author alonso lee
 * 
 */
public class UserPropsBuyHistoryParser extends ALBaseIQParser implements
		IQXmlParseEventCallback {

	ArrayList<Prop> proplist = null;

	@Override
	public void parseIQPackage(ALIQ packact, String stream,
			ALXmppEventListener listener) throws Exception {
		// TODO Auto-generated method stub
		code = 0;
		mListener = listener;
		proplist = null;
		proplist = new ArrayList<Prop>();
		startParse(packact, stream, this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processErrorStartTag(java.lang.String)
	 */
	@Override
	public void processErrorStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals(ERROR_CODE_TAG)) {
			code = ALNumericUtils.parseInt(getAttValue("code"), 0);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processSetStartTag(java.lang.String)
	 */
	@Override
	public void processSetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processGetStartTag(java.lang.String)
	 */
	@Override
	public void processGetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processResultStartTag(java.lang.String)
	 */
	@Override
	public void processResultStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals(ITEM_TAG)) {

			Prop prop = new Prop();
			prop.setPropName(getAttValue("propsname"));
			prop.setPropBuyTime(ALNumericUtils.parseInt(getAttValue("buytime"),
					0));
			prop.setPropDuration(ALNumericUtils.parseInt(
					getAttValue("duration"), 0));
			prop.setMoneyType(getAttValue("moneytype"));
			prop.setPropGold(getAttValue("jindou"));
			prop.setPropRmb(getAttValue("rmb"));
			prop.setPropDollar(getAttValue("dollar"));
			proplist.add(prop);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processEndTag(java.lang.String)
	 */
	@Override
	public void processEndTag(String tag) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processStartDocument()
	 */
	@Override
	public void processStartDocument() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processEndDocument()
	 */
	@Override
	public void processEndDocument() {
		// TODO Auto-generated method stub
		onCallback();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.ALBaseIQParser#onCallback
	 * ()
	 */
	@Override
	public void onCallback() {
		// TODO Auto-generated method stub
		if (mListener != null) {
			mListener.onGetPropsPurchaseInfoListResult(code, proplist);
			ALLog.d("回调道具明细结果 " + code);
		}
	}

}
